{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import sys\n",
    "sys.path.append(os.path.abspath('../'))\n",
    "\n",
    "from common import *\n",
    "\n",
    "fig_name = 'sphere_reparam'\n",
    "\n",
    "fontsize = 12\n",
    "base_size = 4\n",
    "n_rows = 1\n",
    "n_cols = 4\n",
    "total_width = TEXT_WIDTH\n",
    "aspect = n_rows / n_cols * 1.02\n",
    "fig = plt.figure(1, figsize=(total_width, total_width * aspect), constrained_layout=False)\n",
    "gs = fig.add_gridspec(n_rows, n_cols, wspace=0.2, hspace=0.025)\n",
    "\n",
    "titles = ['(a) Integrand', '(b) Vector field $\\partial_{\\pi} \\mathcal{T}$',\n",
    "          '(c) Gradient of original integrand', '(d) Gradient of reparametrized integrand']\n",
    "imgs = ['img_0.exr', 'img_1.exr', 'img_4.exr', 'img_3.exr']\n",
    "\n",
    "for i, img_f in enumerate(imgs):\n",
    "    ax = fig.add_subplot(gs[i])\n",
    "    img = read_img(join(FIGURE_DIR, fig_name, img_f), background_color=[1, 1, 1])\n",
    "    height = img.shape[0]\n",
    "    img = img[:int(height * 0.88), :, :]\n",
    "\n",
    "    aspect = img.shape[0] / img.shape[1]\n",
    "    ax.imshow(img, interpolation='none', extent=[0, 1, 0, aspect])\n",
    "    disable_border(ax)\n",
    "    disable_ticks(ax)\n",
    "    ax.set_title(titles[i], y=-0.1, fontsize=fontsize)\n",
    "\n",
    "    r = 0.978\n",
    "    # Draw sphere outline\n",
    "    arc = matplotlib.patches.Arc([0.502, 0.381], r, r, angle=0.0, theta1=320, theta2=220.0, lw=0.5)\n",
    "    ax.add_patch(arc)\n",
    "    ax.set_ylim(0, aspect)\n",
    "    ax.set_xlim(0, 1)\n",
    "\n",
    "    if i == 0 or i == 1:\n",
    "        # Draw horizon\n",
    "        r = 0.985\n",
    "        arc_back = matplotlib.patches.Arc([0.502, 0.35], r * 0.99, r * 0.2, angle=0.0, theta1=0,\n",
    "                                          theta2=180, lw=0.25, linestyle='--', alpha=0.5)\n",
    "        arc_front = matplotlib.patches.Arc([0.502, 0.35], r * 0.99, r * 0.2, angle=0.0,\n",
    "                                           theta1=180, theta2=0, lw=0.25, linestyle='-')\n",
    "        ax.add_patch(arc_back)\n",
    "        ax.add_patch(arc_front)\n",
    "\n",
    "    if i == 0:\n",
    "        ax.text(s='$\\mathcal{S}^2$', x=0.05, y=0.76)\n",
    "        center = [0.5, 0.35]\n",
    "\n",
    "        ax.arrow(center[0], center[1], -0.15, 0.34, lw=0.25, head_width=0.015, facecolor='k', overhang=0.1)\n",
    "        arrow2_dx = -0.2\n",
    "        arrow2_dy = 0.23\n",
    "        color = [0.4, 0.4, 0.4]\n",
    "        ax.arrow(center[0], center[1], arrow2_dx, arrow2_dy, lw=0.3,\n",
    "                 head_width=0.015, edgecolor=color, facecolor=color, overhang=0.1)\n",
    "\n",
    "        r = 0.7\n",
    "        arc = matplotlib.patches.Arc(center, r * 0.8, r * 1.3, angle=0.0,\n",
    "                                     theta1=114, theta2=133, lw=0.25, linestyle='--')\n",
    "        ax.add_patch(arc)\n",
    "        ax.text(s=r'$\\bm{\\omega}$', x=0.4, y=0.6)\n",
    "        ax.text(s=r'$\\mathcal{T}(\\bm{\\omega}, \\bm{\\pi})$', x=0.3, y=0.45, ha='right', fontsize=12)\n",
    "        r = 0.005\n",
    "        arc = matplotlib.patches.Circle(center, r, lw=0.05, facecolor='k')\n",
    "        ax.add_patch(arc)\n",
    "        r = 0.01\n",
    "        arc = matplotlib.patches.Circle([center[0] - 0.165, center[1] + 0.34 + 0.03], r, lw=0.05, facecolor='k')\n",
    "        ax.add_patch(arc)\n",
    "        arc = matplotlib.patches.Circle([center[0] + arrow2_dx - 0.03, center[1] +\n",
    "                                        arrow2_dy + 0.03], r, lw=0.05, facecolor='k')\n",
    "        ax.add_patch(arc)\n",
    "        flip_arrows = True\n",
    "        color = [0.2, 0.4, 0.7]\n",
    "        origins = [[0.8, 0.357], [0.74, 0.375], [0.67, 0.365], [0.58, 0.346]]\n",
    "        deltas = [[-0.003, -0.017], [-0.003, -0.025], [-0.003, -0.025], [-0.003, -0.022]]\n",
    "        for o, d in zip(origins, deltas):\n",
    "            if flip_arrows:\n",
    "                ax.arrow(o[0] + d[0], o[1] + d[1] - 0.029, -d[0], -d[1],\n",
    "                         head_width=0.02, edgecolor=color, facecolor=color, overhang=0.1)\n",
    "            else:\n",
    "                ax.arrow(o[0], o[1], d[0], d[1], head_width=0.02, edgecolor=color, facecolor=color)\n",
    "        ax.text(s='$\\pi$', x=0.82, y=0.32)\n",
    "\n",
    "plt.margins(0, 0)\n",
    "# save_fig(fig_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('mi')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "c8cc192903caa17681aa39d71202092ac11a526d37a1c4ad2948f13605924304"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
